<template>
  <div>
    <div class="app-container clearfix pageHeader">
      <div class="header fl">{{$route.meta.title}}</div>
    </div>

    <div class="app-container margin-content padding-content">
      <el-form
        label-position="right"
        :model="dataForm"
        ref="dataForm"
        label-width="80px">

        <el-row :gutter="48">
          <el-col :sm="24" :md="8">
            <el-form-item label="日期区间" prop="time">
              <el-date-picker
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                unlink-panels
                value-format="yyyy-MM-dd"
                v-model="dataForm.time"
                :picker-options="pickerOptions"
                style="width: 100%;"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :sm="24" :md="6" v-if="false">
            <el-form-item label="是否在港" prop="isInPort">
              <el-select v-model="dataForm.isInPort" clearable placeholder="请选择" style="width: 100%;">
                <el-option key="0" label="在港" value="0"></el-option>
                <el-option key="1" label="离港" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :sm="24" :md="6" v-if="false">
            <el-form-item label="是否重号" prop="isRepeat">
              <el-select v-model="dataForm.isRepeat" clearable placeholder="请选择" style="width: 100%;">
                <el-option key="0" label="是" value="0"></el-option>
                <el-option key="1" label="否" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :sm="24" :md="6">
            <el-form-item label="处理情况" prop="dealStatus">
              <el-select v-model="dataForm.dealStatus" placeholder="请选择" clearable style="width: 100%;">
                <el-option key="0" label="未处理" value="0"></el-option>
                <el-option key="1" label="已处理" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :sm="24" :md="6">
            <el-button type="primary" @click="handleSearch">查询</el-button>
          </el-col>
        </el-row>


        <!--<div style="text-align: right">-->
        <!--<el-button type="primary" @click="handleSearch">查询</el-button>-->
        <!--</div>-->
      </el-form>
    </div>


    <div class="app-container margin-content padding-content">
      <el-table
        :key="tableKey"
        :data="tableData"
        v-loading="loading"
        element-loading-text="正在加载..."
        :highlight-current-row="true"
        style="width: 100%;"
        :max-height="scrollHeight">

        <el-table-column label="集装箱号/提单号" property="recordNo" width="120" fixed="left">
          <template slot-scope="scope">
            <a @click="view(scope.row.recordNo)">{{scope.row.recordNo}}</a>
          </template>
        </el-table-column>
        <el-table-column label="集装箱校验码" property="checkCode" width="100"></el-table-column>
        <el-table-column label="首次发现日期" property="createdtime" width="130">
          <template slot-scope="scope">
            {{scope.row.createdtime | parseTime}}
          </template>
        </el-table-column>
        <el-table-column label="最新状态" header-align="center">
          <el-table-column label="进出口" property="ieFlag">
            <template slot-scope="scope">
              {{scope.row.ieFlag | ieFlagFilter}}
            </template>
          </el-table-column>
          <el-table-column label="作业类型" property="actType" width="130">
            <template slot-scope="scope">
              {{scope.row.actType | activityTypeFilter}}
            </template>
          </el-table-column>
          <el-table-column label="作业时间" property="actTime" width="130">
            <template slot-scope="scope">
              {{scope.row.actTime | parseTime}}
            </template>
          </el-table-column>
          <el-table-column label="重吉" property="leFlag">
            <template slot-scope="scope">
              {{scope.row.leFlag | leFlagFilter}}
            </template>
          </el-table-column>
          <el-table-column label="集装箱尺寸" property="sizeId" width="100"></el-table-column>
          <el-table-column label="堆场位置" property="yardCode"></el-table-column>
        </el-table-column>
        <el-table-column label="港口" property="portCode" width="120">
          <template slot-scope="scope">
            {{scope.row.portCode | portCodeFilter}}
          </template>
        </el-table-column>
        <el-table-column label="处理情况" width="90" fixed="right">
          <template slot-scope="scope">
            <el-popover
              placement="top"
              title="处理情况"
              width="500"
              trigger="click"
              :disabled="!scope.row.dealTime" style="cursor:pointer">

              <el-table
                :key="1"
                :data="[scope.row]"
                style="width: 100%;">
                <el-table-column property="recordNum" label="序列号"></el-table-column>
                <el-table-column property="operatorName" label="处理人"></el-table-column>
                <el-table-column property="dealTime" label="处理时间" width="130">
                  <template slot-scope="scope">
                    {{scope.row.dealTime | parseTime}}
                  </template>
                </el-table-column>
                <el-table-column property="dealType" label="处理意见" v-if="!scope.row.dealDetail">
                  <template slot-scope="scope">
                    {{ scope.row.dealType | dealTypeFilter}}
                  </template>
                </el-table-column>
                <el-table-column property="dealDetail" label="处理意见" v-if="scope.row.dealDetail"></el-table-column>
              </el-table>

              <el-tag type="success" slot="reference" v-if="scope.row.dealTime">已处理</el-tag>
              <el-tag type="warning" slot="reference" v-else>未处理</el-tag>
            </el-popover>

          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" v-if="hasPermission([0,270,282,283])">
          <template slot-scope="scope">
            <a @click="handleUpdate({id:scope.row.id, dealRecordNo:scope.row.recordNo,recordSource:3})">处理</a>
          </template>
        </el-table-column>
      </el-table>


      <div class="pagination-container align-right" v-show="tableData.length > 0">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="dataForm.pageNum"
          :page-sizes="pageSizes"
          :page-size="dataForm.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>

    <!-- 弹窗, 情况处理 -->
    <warning-handle v-if="handleVisible" ref="handle" @refresh="_contNoErrorFetchList()"></warning-handle>
    <!-- 弹窗, 最新动态 -->
    <cont-detail-dialog v-if="contDetailVisible" ref="contDetail"></cont-detail-dialog>
  </div>
</template>

<script>
  // api
  import { contNoErrorFetchList } from '@/api/storageWarning'
  // utils
  import { pickerOptions, getLately } from '@/utils'
  import { page } from '@/utils/page'
  import { hasPermission } from '@/utils/permission' //判断是否有权限，返回bollean值

  // vuex
  import { mapMutations } from 'vuex'
  // components
  import ContDetailDialog from '@/components/ContDetailDialog'
  import WarningHandle from '@/components/WarningHandle'

  const time = getLately(0)

  export default {
    name: 'containerNumWarning',
    data() {
      return {
        hasPermission: hasPermission,
        tableKey: 0,
        tableData: [],
        loading: false,
        scrollHeight: null,
        dataForm: {
          time: null,
          isInPort: '',
          isRepeat: '',
          dealStatus: null,
          pageNum: 1,
          pageSize: page.pageSize
        },
        pageSizes: page.pageSizes,
        total: 0,
        pickerOptions: {
          shortcuts: pickerOptions
        },
        handleVisible: false,
        contDetailVisible: false
      }
    },
    created() {
      this._contNoErrorFetchList()
      this.tableResize()
    },
    methods: {
      tableResize() {
        const _height = 380
        this.scrollHeight = document.body.scrollHeight - _height
        window.onresize = () => {
          this.scrollHeight = document.body.scrollHeight - _height
        }
      },
      _contNoErrorFetchList() {
        this.loading = true
        this.tableData = []
        contNoErrorFetchList(this.dataForm).then((res) => {
          this.tableData = res.data.data.dataList
          this.total = res.data.data.total
          this.loading = false
        })
      },
      handleSearch() {
        this.dataForm.pageNum = 1
        this._contNoErrorFetchList()
      },
      handleSizeChange(val) {
        this.dataForm.pageSize = val
        this._contNoErrorFetchList()
      },
      handleCurrentChange(val) {
        this.dataForm.pageNum = val
        this._contNoErrorFetchList()
      },
      view(id) {
        this.contDetailVisible = true
        this.$nextTick(() => {
          this.setCurrentId(id)
          this.$refs['contDetail'].init()
        })
      },
      handleUpdate({id, dealRecordNo, recordSource}) {
        this.handleVisible = true
        this.$nextTick(() => {
          this.setCurrentId({id, dealRecordNo, recordSource})
          this.$refs['handle'].init()
        })
      },
      ...mapMutations({
        setCurrentId: 'SET_CURRENTID'
      })
    },
    components: {
      ContDetailDialog,
      WarningHandle
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped="scope">

</style>
